package cn.lxh.autoconfigure;

import cn.lxh.pojo.properties.WxPayProperties;
import cn.lxh.template.WxPayTemplate;
import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
@EnableConfigurationProperties({WxPayProperties.class})
public class PayAutoConfiguration {


    @Bean
    public WxPayTemplate wxPayTemplate(WxPayProperties properties){
        // 一个商户号只能初始化一个配置，否则会因为重复的下载任务报错
        Config config = new RSAAutoCertificateConfig.Builder()
                .merchantId(properties.getMerchantId())
                .privateKeyFromPath(properties.getPrivateKeyPath())
                .merchantSerialNumber(properties.getMerchantSerialNumber())
                .apiV3Key(properties.getApiV3Key())
                .build();
        return new WxPayTemplate(properties, config);
    }
}